import Vue from 'vue'
import Router from 'vue-router'
import Cms from './views/Cms.vue'
Vue.use(Router)



// 控制台路由
const CmsPage = [
  {
    path: '/cms',
    name: 'cms',
    component: Cms,
    redirect: '/cms/index',
    children: [
      {
        icon: 'el-icon-s-home',
        meta: {
          title: '首页商品展示',
        },
        path: '/cms/index',
        name: 'cms_index',
        component: () => import(/* webpackChunkName: "cms_index" */ '@/views/CmsPage/Index.vue')
      },
      {
        icon: 'el-icon-s-custom',
        path: '/cms/user',
        name: "cms_user",
        meta: {
          title: '商品中心',
        },
        redirect: '/cms/user/basic',
        component: { render: h => h("router-view") },  // 子路由需要添加
        children: [
          {
            meta: {
              title: '商品分类',
            },
            name: "cms_basic",
            path: '/cms/user/basic',
            component: () => import(/* webpackChunkName: "cms_basic" */ '@/views/CmsPage/UserCenter/Basic.vue')
          },
          {
            meta: {
              title: '商品列表',
              hide:true
            },
            name: "good_list",
            path: '/cms/user/good_list',
            component: () => import(/* webpackChunkName: "good_list" */ '@/views/CmsPage/UserCenter/GoodList.vue')
          },
          {
            meta: {
              title: '主题',
            
            },
            name: "theme",
            path: '/cms/user/theme',
            component: () => import(/* webpackChunkName: "theme" */ '@/views/CmsPage/UserCenter/Theme.vue')
          },
          

        ]
      },
      

    ]
  }
]


// homepage cmspage 位置请不要改变
const router = new Router({
  routes: [
    {
      path: '/',
      redirect: '/cms'
    },
    ...CmsPage,
    {
      path: '/login',
      component: () => import(/* webpackChunkName: "login" */ '@/views/Login.vue')
    },
    {
      path: "*",
      component: () => import(/* webpackChunkName: "not_found" */ '@/views/404.vue')
    }
  ]
})



// 路由钩子函数
// router.beforeEach((to, from, next) => {
//   const token = localStorage.getItem('user_token');
//   if (token) {
//     //有令牌
//     if (to.path === '/login') {
//       next({ path: '/home/index' })
//     } else {
//       next()
//     }
//   } else {

//     //无令牌
//     if (to.path.includes('/home') || to.path.includes('/login')) {
//       next()
//     } else {
//       Notification.error({
//         title: '提示',
//         message: '请您先登陆',
//         duration: 3000
//       });
//       next({ path: login_page })
//     }
//   }
// })

// router.afterEach((to, from) => {
//   // NProgress.done()
// })


export default router

